Incremental-type encoders and absolute-type encoders for detecting the rotational position of the motor shaft of an AC servomotor require an optical or magnetic detector in order to ensure a predetermined resolution. A space for providing the detector must therefore be maintained at the rear end portion of the motor rotational shaft or elsewhere. A high-precision encoder plate and other expensive components are also necessary. As a result, it is sometimes difficult to maintain a space for building an encoder into a flat motor or the like having a short shaft length. The cost of the encoder and the motor into which the encoder is built also increase.